<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>embedme: src/NetUtil.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">embedme
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">NetUtil.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_net_util_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * This file is part of libemb.</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * libemb is free software: you can redistribute it and/or modify</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * (at your option) any later version.</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * libemb is distributed in the hope that it will be useful,</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * GNU General Public License for more details.</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * along with libemb.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * Project: Embedme</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * Author : FergusZeng</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> * Email  : cblock@126.com</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> * git    : https://gitee.com/newgolo/embedme.git</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> * Copyright 2014~2020 @ ShenZhen ,China</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment">*******************************************************************************/</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#ifndef __NET_UTIL_H__</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#define __NET_UTIL_H__</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#ifdef OS_CYGWIN</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#else</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_base_type_8h.html">BaseType.h</a>&quot;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="keyword">namespace </span>libemb{</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160; </div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="_net_util_8h.html#aa652d8a6638e8367e3aa0c8c005f847a">   40</a></span>&#160;<span class="keyword">enum class</span> <a class="code" href="_net_util_8h.html#aa652d8a6638e8367e3aa0c8c005f847a">NetHwState</a></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;{</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    Down,   </div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    Up,     </div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    Error</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;};</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="_net_util_8h.html#a30af18f263a539852711bbd271e9a9d8">   51</a></span>&#160;<span class="keyword">enum class</span> <a class="code" href="_net_util_8h.html#a30af18f263a539852711bbd271e9a9d8">NetLinkState</a></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;{</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    Disconnected,   </div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    Connected,      </div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    Error</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;};</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno"><a class="line" href="classlibemb_1_1_net_util.html">   62</a></span>&#160;<span class="keyword">class </span><a class="code" href="classlibemb_1_1_net_util.html">NetUtil</a>{</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <a class="code" href="classlibemb_1_1_net_util.html">NetUtil</a>();</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    ~<a class="code" href="classlibemb_1_1_net_util.html">NetUtil</a>();</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_net_util.html#a6fcc0212b4788d7c84b1d530b8e7cd51">isValidIP</a>(<span class="keyword">const</span> std::string ip);</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_net_util.html#a0e7a71af2ed0868ac32d4daa40980bfa">checkSubnetIP</a>(<span class="keyword">const</span> std::string gatewayIP,<span class="keyword">const</span> std::string subnetMask,std::string&amp; subnetIP);</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="keyword">static</span> std::string <a class="code" href="classlibemb_1_1_net_util.html#a0d989b9d5c1a2f7a52e54cfa7452b297">getSubnetIP</a>(<span class="keyword">const</span> std::string gatewayIP,<span class="keyword">const</span> std::string subnetMask,<span class="keywordtype">int</span> subIndex);</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <span class="keyword">static</span> std::string <a class="code" href="classlibemb_1_1_net_util.html#a488d0c73136bcf3f489b57096d5bfb2b">getInetAddr</a>(<span class="keyword">const</span> std::string intf);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    <span class="keyword">static</span> std::string <a class="code" href="classlibemb_1_1_net_util.html#ad4bdfc20f3cc038fef56aba30899fd7e">getMaskAddr</a>(<span class="keyword">const</span> std::string intf);</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    <span class="keyword">static</span> std::string <a class="code" href="classlibemb_1_1_net_util.html#a686ec370867d03c670eff586287acd38">getMacAddr</a>(<span class="keyword">const</span> std::string intf);</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;    <span class="keyword">static</span> <a class="code" href="_net_util_8h.html#aa652d8a6638e8367e3aa0c8c005f847a">NetHwState</a> <a class="code" href="classlibemb_1_1_net_util.html#aeab3247907bbacb5fb3ead4b5cf1a758">getHwState</a>(<span class="keyword">const</span> std::string intf);</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    <span class="keyword">static</span> <a class="code" href="_net_util_8h.html#a30af18f263a539852711bbd271e9a9d8">NetLinkState</a> <a class="code" href="classlibemb_1_1_net_util.html#aa56ecf7efb5269453a0957c83ba0203c">getLinkState</a>(<span class="keyword">const</span> std::string intf);</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_net_util.html#a03ad01a91fa4506495d13a2e1f1df927">setInetAddr</a>(<span class="keyword">const</span> std::string intf,<span class="keyword">const</span> std::string ipaddr);</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_net_util.html#a4bb38b696c79d1d00e28397efb50ad60">setMaskAddr</a>(<span class="keyword">const</span> std::string intf,<span class="keyword">const</span> std::string netmask);</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_net_util.html#a07625066943cbfa53a6ce1bfbcb03924">setMacAddr</a>(<span class="keyword">const</span> std::string intf,<span class="keyword">const</span> std::string mac);</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_net_util.html#a4072f4022df07fafd6627fbb250f444b">setHwState</a>(<span class="keyword">const</span> std::string intf, <a class="code" href="_net_util_8h.html#aa652d8a6638e8367e3aa0c8c005f847a">NetHwState</a> state);</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160; </div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    <span class="keyword">static</span> std::string <a class="code" href="classlibemb_1_1_net_util.html#a2021b10ef7684c18ea9a14a7672158c0">getHostIP</a>(<span class="keyword">const</span> std::string&amp; hostName);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;};</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;}</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;<span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a4bb38b696c79d1d00e28397efb50ad60"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a4bb38b696c79d1d00e28397efb50ad60">libemb::NetUtil::setMaskAddr</a></div><div class="ttdeci">static bool setMaskAddr(const std::string intf, const std::string netmask)</div><div class="ttdoc">设置子网掩码</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:350</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_aeab3247907bbacb5fb3ead4b5cf1a758"><div class="ttname"><a href="classlibemb_1_1_net_util.html#aeab3247907bbacb5fb3ead4b5cf1a758">libemb::NetUtil::getHwState</a></div><div class="ttdeci">static NetHwState getHwState(const std::string intf)</div><div class="ttdoc">获取网口状态</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:250</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a2021b10ef7684c18ea9a14a7672158c0"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a2021b10ef7684c18ea9a14a7672158c0">libemb::NetUtil::getHostIP</a></div><div class="ttdeci">static std::string getHostIP(const std::string &amp;hostName)</div><div class="ttdoc">获取域名对应的IP</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:477</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a0e7a71af2ed0868ac32d4daa40980bfa"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a0e7a71af2ed0868ac32d4daa40980bfa">libemb::NetUtil::checkSubnetIP</a></div><div class="ttdeci">static bool checkSubnetIP(const std::string gatewayIP, const std::string subnetMask, std::string &amp;subnetIP)</div><div class="ttdoc">校验子网IP</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:87</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html"><div class="ttname"><a href="classlibemb_1_1_net_util.html">libemb::NetUtil</a></div><div class="ttdoc">网络工具类,提供对网络设别的常用操作.</div><div class="ttdef"><b>Definition:</b> NetUtil.h:62</div></div>
<div class="ttc" id="a_net_util_8h_html_aa652d8a6638e8367e3aa0c8c005f847a"><div class="ttname"><a href="_net_util_8h.html#aa652d8a6638e8367e3aa0c8c005f847a">libemb::NetHwState</a></div><div class="ttdeci">NetHwState</div><div class="ttdoc">网络硬件状态</div><div class="ttdef"><b>Definition:</b> NetUtil.h:41</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_ad4bdfc20f3cc038fef56aba30899fd7e"><div class="ttname"><a href="classlibemb_1_1_net_util.html#ad4bdfc20f3cc038fef56aba30899fd7e">libemb::NetUtil::getMaskAddr</a></div><div class="ttdeci">static std::string getMaskAddr(const std::string intf)</div><div class="ttdoc">获取网口子网掩码地址</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:180</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_aa56ecf7efb5269453a0957c83ba0203c"><div class="ttname"><a href="classlibemb_1_1_net_util.html#aa56ecf7efb5269453a0957c83ba0203c">libemb::NetUtil::getLinkState</a></div><div class="ttdeci">static NetLinkState getLinkState(const std::string intf)</div><div class="ttdoc">获取网络连接状态</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:286</div></div>
<div class="ttc" id="a_base_type_8h_html"><div class="ttname"><a href="_base_type_8h.html">BaseType.h</a></div><div class="ttdoc">基础类型头文件</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a03ad01a91fa4506495d13a2e1f1df927"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a03ad01a91fa4506495d13a2e1f1df927">libemb::NetUtil::setInetAddr</a></div><div class="ttdeci">static bool setInetAddr(const std::string intf, const std::string ipaddr)</div><div class="ttdoc">设置网口IP</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:307</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a0d989b9d5c1a2f7a52e54cfa7452b297"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a0d989b9d5c1a2f7a52e54cfa7452b297">libemb::NetUtil::getSubnetIP</a></div><div class="ttdeci">static std::string getSubnetIP(const std::string gatewayIP, const std::string subnetMask, int subIndex)</div><div class="ttdoc">获取子网IP</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:121</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a07625066943cbfa53a6ce1bfbcb03924"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a07625066943cbfa53a6ce1bfbcb03924">libemb::NetUtil::setMacAddr</a></div><div class="ttdeci">static bool setMacAddr(const std::string intf, const std::string mac)</div><div class="ttdoc">设置MAC地址</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:392</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a686ec370867d03c670eff586287acd38"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a686ec370867d03c670eff586287acd38">libemb::NetUtil::getMacAddr</a></div><div class="ttdeci">static std::string getMacAddr(const std::string intf)</div><div class="ttdoc">获取网口mac地址</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:216</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a4072f4022df07fafd6627fbb250f444b"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a4072f4022df07fafd6627fbb250f444b">libemb::NetUtil::setHwState</a></div><div class="ttdeci">static bool setHwState(const std::string intf, NetHwState state)</div><div class="ttdoc">设置网口状态</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:430</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a488d0c73136bcf3f489b57096d5bfb2b"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a488d0c73136bcf3f489b57096d5bfb2b">libemb::NetUtil::getInetAddr</a></div><div class="ttdeci">static std::string getInetAddr(const std::string intf)</div><div class="ttdoc">获取网口ip地址</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:143</div></div>
<div class="ttc" id="a_net_util_8h_html_a30af18f263a539852711bbd271e9a9d8"><div class="ttname"><a href="_net_util_8h.html#a30af18f263a539852711bbd271e9a9d8">libemb::NetLinkState</a></div><div class="ttdeci">NetLinkState</div><div class="ttdoc">网络连接状态</div><div class="ttdef"><b>Definition:</b> NetUtil.h:52</div></div>
<div class="ttc" id="aclasslibemb_1_1_net_util_html_a6fcc0212b4788d7c84b1d530b8e7cd51"><div class="ttname"><a href="classlibemb_1_1_net_util.html#a6fcc0212b4788d7c84b1d530b8e7cd51">libemb::NetUtil::isValidIP</a></div><div class="ttdeci">static bool isValidIP(const std::string ip)</div><div class="ttdoc">判断是否是合法IP</div><div class="ttdef"><b>Definition:</b> NetUtil.cpp:73</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
</html>
